<template>
	<view>
		<view v-if="identifyState == 0">
			<view class="contenter">
				<view class="cu-form-group">
					<view class="title">姓名</view>
					<input v-model="ownName" placeholder="请输入姓名" class="text-right"></input>
				</view>

				<view class="cu-form-group">
					<view class="title">身份类型</view>
					<picker bindchange="PickerChange" :value="index" :range="ownCloums" @change="roomChange">
						<view class="picker">
							{{ownType?ownType:'请选择'}}
						</view>
					</picker>
				</view>

				<view class="cu-form-group">
					<view class="title">手机号</view>
					<input v-model="ownTel" placeholder="请输入手机号" class="text-right"></input>
				</view>
			</view>

			<view class="subBtn">
				<button type="primary" @click="submitBtn">提交</button>
			</view>
		</view>
		<view v-if="identifyState != 0">
			<view class="block__title">基本信息</view>

			<view class="cu-form-group">
				<view class="title">姓名</view>
				{{ownInfo.name}}
			</view>

			<view class="cu-form-group">
				<view class="title">身份类型</view>
				{{ownInfo.identityCard}}
			</view>

			<view class="cu-form-group">
				<view class="title">手机号</view>
				{{ownInfo.phone}}
			</view>

		</view>
	</view>

	</view>
</template>

<script>
	import context from '../../lib/java110/Java110Context.js';
	const constant = context.constant;
	export default {
		data() {
			return {
				ownInfo: '',
				identifyState: '', //绑定状态
				ownCloums: [], //身份类型数据
				ownType: "", //选择的类型
				ownId: '',
				ownTel:'',
				ownName:'',
			};
		},
		onLoad: function(options) {
			let that = this;
			// 身份类型选择
			uni.request({
				url: "http://localhost:8888/identify",
				post: "get",
				success: (res) => {
					console.log("123", res.data)
					this.identifyState = res.code
					let arr = res.data.data;
					let ownCloums = [];
					let userId = [];
					arr.map(item => {
						ownCloums.push(item.identifyType);
						userId.push(item.id);
					})
					that.ownCloums = ownCloums;
					that.userId = userId;
				}
			})

			this.loadOwnerInfo();
		},
		methods: {
			// 选择身份
			roomChange: function(e) {
				this.ownId = this.userId[e.detail.value];
				this.ownType = this.ownCloums[e.detail.value];
			},
			// 查询绑定信息
			loadOwnerInfo() {
				uni.request({
					url: constant.url.ownerInfo,
					method: "GET",
					success: (res) => {
						this.ownInfo = res.data.result
						console.log("res", this.ownInfo)
					},
					fail: function(e) {
						wx.showToast({
							title: "服务器异常了",
							icon: 'none',
							duration: 2000
						});
					}
				});
			},
			// 提交鉴定信息
			submitBtn: function(e) {

				let obj = {
						"repairName": this.ownName,
						"repairType": this.ownCloums,
						"tel": this.ownTel,
						"ownId": this.ownId
					};
					let msg = "";
				
					if (obj.repairName == "") {
						msg = "请填写姓名";
					} else if (obj.tel == "") {
						msg = "请填写手机号";
					} else if (obj.repairType == '') {
						msg = "请选择身份类型";
					} else if (obj.ownId == "") {
						msg = "请填写身份ID";
					}
				
					if (msg != "") {
						wx.showToast({
							title: msg,
							icon: 'none',
							duration: 2000
						});
					} else {
						console.log("提交数据", obj);
						uni.request({
							url: constant.url.complaintsSubmit,
							// header: context.getHeaders(),
							method: "POST",
							data: obj,
							//动态数据
							success: function(res) {
								let _json = res.data;
								// if (_json.code == 0) {
									uni.redirectTo({
										url: '/pages/viewBindOwner/viewBindOwner',
									});
									return;
								// }
								wx.showToast({
									title: "服务器异常了",
									icon: 'none',
									duration: 2000
								})
							},
							fail: function(e) {
								console.log(e);
								wx.showToast({
									title: "服务器异常了",
									icon: 'none',
									duration: 2000
								});
							}
						});
					}
				},
				
			// },
		}
	}
</script>

<style lang="scss" scoped>
	.contenter {
		width: 100%;
		height: calc(100vh - 100rpx);
		overflow: auto;
	}

	.subBtn {
		osition: relative;
		display: flex;
		justify-content: center;
		align-items: center;

		button {
			width: 350rpx;
			height: 70rpx;
			border-radius: 30rpx;
			text-align: center;
			line-height: 70rpx;
			// font-size: ;
		}
	}
</style>
